package com.lsh.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lsh.anno.DataSource;
import com.lsh.entity.Day27User;
import com.lsh.entity.QuartzUser;
import com.lsh.enu.DataSourceType;
import com.lsh.mapper.Day27UserMapper;
import com.lsh.mapper.QuartzUserMapper;
import com.lsh.repository.Day27UserRepository;
import com.lsh.repository.QuartzUserRepository;
import com.lsh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：LiuShihao
 * @date ：Created in 2021/5/21 9:58 上午
 * @desc ：
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    Day27UserRepository day27UserRepository;

    @Autowired
    QuartzUserRepository quartzUserRepository;

    @Resource
    Day27UserMapper day27UserMapper;

    @Resource
    QuartzUserMapper quartzUserMapper;

    /**
     * 持久层使用JPA
     * @return
     */
    @Override
    @DS("master")
    public List<Day27User> findDay27User(){
        List<Day27User> all = day27UserRepository.findAll();
        return all;
    }

    /**
     * 持久层使用JPA
     * @return
     */
    @Override
    @DS("slave_1")
    public List<QuartzUser> findQuartzUser(){
        List<QuartzUser> all = quartzUserRepository.findAll();
        return all;
    }

    /**
     * 持久层使用MyBatis
     * @return
     */
    @Override
    @DS("master")
    public List<Day27User> findDay27UserByMyBatis() {
        return day27UserMapper.findAll();
    }
    /**
     * 持久层使用MyBatis
     * @return
     */
    @Override
    @DS("slave_1")
    public List<QuartzUser> findQuartzUserByMyBatis() {
        return quartzUserMapper.findAll();
    }



    @DataSource(DataSourceType.MASTER)
    @Override
    public List<Day27User> findDay27UserByRuoyi() {
        return day27UserRepository.findAll();
    }
    @DataSource(DataSourceType.SLAVE)
    @Override
    public List<QuartzUser> findQuartzUserByRuoyi() {
        return quartzUserRepository.findAll();
    }

}
